# -*- coding: utf-8 -*-
# @author: wch
# @file: video_to_img.py
# @time: 2023/2/2 16:42

import os
import cv2


def video_to_img(video_path, img_path, name=None):
    cap = cv2.VideoCapture(video_path)
    count = 0
    # 摄像头是否为打开状态
    while cap.isOpened():
        # ret返回为布尔值，True为有返回，Fasle返回为空
        ret, frame = cap.read()
        if ret:
            cv2.imwrite(img_path + "\\" + name + str(count) + ".jpg", frame)
            count += 1
        else:
            break


if __name__ == '__main__':
    video_path = r"E:\dyk\opencv\media\two_video.mp4"
    img_path = r"E:\dyk\opencv\media\jxq"
    video_to_img(video_path, img_path, "jxq")
